/////////////////////////////////////////////////////////////////////////////
// Name:        payment.cpp
// Purpose:     
// Author:      Herry Sugiharto
// Modified by: 
// Created:     17/09/2008 23:00:36
// RCS-ID:      
// Copyright:   Copyright (c) 2000, 2008 Krida Software Division
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "payment.h"

////@begin XPM images
////@end XPM images


/*!
 * Payment type definition
 */

IMPLEMENT_DYNAMIC_CLASS( Payment, wxDialog )


/*!
 * Payment event table definition
 */

BEGIN_EVENT_TABLE( Payment, wxDialog )

////@begin Payment event table entries
    EVT_BUTTON( wxID_OK, Payment::OnOkClick )

    EVT_BUTTON( wxID_CANCEL, Payment::OnCancelClick )

////@end Payment event table entries

END_EVENT_TABLE()


/*!
 * Payment constructors
 */

Payment::Payment()
{
    Init();
}

Payment::Payment( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * Payment creator
 */

bool Payment::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin Payment creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end Payment creation
    return true;
}


/*!
 * Payment destructor
 */

Payment::~Payment()
{
////@begin Payment destruction
////@end Payment destruction
}


/*!
 * Member initialisation
 */

void Payment::Init()
{
////@begin Payment member initialisation
    GrandTotal = 0;
    PaymentAmount = 0;
////@end Payment member initialisation
}


/*!
 * Control creation for Payment
 */

void Payment::CreateControls()
{    
////@begin Payment content construction
    Payment* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Grand Total"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl5 = new wxTextCtrl( itemDialog1, ID_TEXT_TOTAL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_RIGHT );
    itemBoxSizer3->Add(itemTextCtrl5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer6, 0, wxGROW|wxALL, 5);

    wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("Payment"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl8 = new wxTextCtrl( itemDialog1, ID_TEXT_PAYMENT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_RIGHT );
    itemBoxSizer6->Add(itemTextCtrl8, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer9 = new wxStdDialogButtonSizer;

    itemBoxSizer2->Add(itemStdDialogButtonSizer9, 0, wxGROW|wxALL, 5);
    wxButton* itemButton10 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton10->SetDefault();
    itemStdDialogButtonSizer9->AddButton(itemButton10);

    wxButton* itemButton11 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer9->AddButton(itemButton11);

    itemStdDialogButtonSizer9->Realize();

    // Set validators
    itemTextCtrl5->SetValidator( wxGenericValidator(& GrandTotal) );
    itemTextCtrl8->SetValidator( wxGenericValidator(& PaymentAmount) );
////@end Payment content construction
    
    itemTextCtrl8->SetFocus();
}


/*!
 * Should we show tooltips?
 */

bool Payment::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap Payment::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin Payment bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end Payment bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon Payment::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin Payment icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end Payment icon retrieval
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
 */

void Payment::OnOkClick( wxCommandEvent& event )
{
    wxUnusedVar(event);
    TransferDataFromWindow();
    if (PaymentAmount >= GrandTotal) {
        Change = PaymentAmount - GrandTotal;
        EndModal(wxID_OK);
    } else {
        wxMessageBox(wxT("Error in Payment amount!"), wxT("Payment"), wxICON_ERROR);
    };
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
 */

void Payment::OnCancelClick( wxCommandEvent& event )
{
    wxUnusedVar(event);
    EndModal(wxID_CANCEL);
}

